﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace XQ.Framework.thread
{
    public class Task
    {
        private Timer timer = null;
        public Action handler { get; set; }
        private void Run(object obj)
        {
            try
            {
                if (handler == null) { return; }
                handler.Invoke();
            }
            catch (Exception e)
            { 
            }
        }
        public void Start()
        {
            if (timer == null)
            {
                timer = new Timer(new TimerCallback(Run), null, 1000, 1000);
            }
        }
        public void ReStart()
        {
            if (timer != null)
            {
                timer.Change(1000, 1000);
            }
        }
        public void Stop()
        {
            if (timer != null)
            {
                timer.Dispose();
            }
        }
    }
}
